package Calculator;
	import java.awt.event.ActionEvent;
	import java.awt.event.ActionListener;
	import java.io.File;

	import javax.swing.JButton;
	import javax.swing.JFileChooser;
	import javax.swing.JFrame;
	import javax.swing.JLabel;
	import javax.swing.JTextField;
	import javax.swing.SwingUtilities;

	public class FileCopy extends JFrame implements ActionListener{
		private static final long serialVersionUID = 1L;
		private JButton[] bt=new JButton[2];
		private JTextField[] tf=new JTextField[2];
		private File srcFile;
		public FileCopy() {
			setSize(500, 500);
			setVisible(true);
			setDefaultCloseOperation(EXIT_ON_CLOSE);
			
			setLayout(null);
			
			String[] str={"选择文件","存放位置"};
			for(int i=0;i<str.length;i++){
				JLabel label=new JLabel(str[i]);
				label.setBounds(50, 40+i*50, 70, 25);
				add(label);
				label=new JLabel(str[i]);
				tf[i].setBounds(120, 40+i*50, 200, 25);
				add(tf[i]);
				bt[i]=new JButton("...");
				bt[i].setBounds(330, 40+i*50, 60, 25);
				bt[i].addActionListener(this);
				add(bt[i]);
			}
			
			JButton cpbt=new JButton("复制");
			cpbt.setBounds(130, 330, 200, 25);
			add(cpbt);
		}
		
		public static void main(String[] args) {
			SwingUtilities.invokeLater(new Runnable() {
				
				@Override
				public void run() {
					new FileCopy();
				}
			});
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			Object o=e.getSource();
						
			if(o==bt[0]){
				JFileChooser fc=new JFileChooser();
				int f=fc.showOpenDialog(this);
				if(f==JFileChooser.APPROVE_OPTION){
					srcFile=fc.getSelectedFile();
					tf[0].setText(srcFile.getPath());
				}
			}
			else if(o==bt[1]){
				JFileChooser fc=new JFileChooser();
				fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				int f=fc.showOpenDialog(this);
				if(f==JFileChooser.APPROVE_OPTION){				
					tf[1].setText(fc.getSelectedFile().getPath());
				}
			}
			
		}

	}

